using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Services.Activity.Domain.Entities;

namespace Services.Activity.Infrastructure.Configs;
public class VoluntaryActivityConfig : IEntityTypeConfiguration<VoluntaryActivity>
{
    public void Configure(EntityTypeBuilder<VoluntaryActivity> builder)
    {
        builder.ToTable("T_VoluntaryActivity");
        builder.HasKey(x => x.ActivityId).IsClustered(true);
        builder.Property(x => x.ActivityId).UseHiLo();
        builder.Ignore(o => o.Id);
        builder.Property(x => x.ActivityType).HasConversion<string>();
        builder.HasMany(x=>x.Volunteers).WithOne().HasForeignKey(x=>x.ActivityId).IsRequired();
        builder.HasMany(x=>x.Reviews).WithOne().HasForeignKey(x=>x.ActivityId).IsRequired();
        builder.HasQueryFilter(x => x.IsDeleted == false);
        builder.HasIndex(x=>x.ActivityComplete).HasDatabaseName("IX_VoluntaryActivity_ActivityComplete");
    }
}